package com.system.registrationPool.controller;

import com.system.registrationPool.bean.RegistrationPoolList;
import com.system.registrationPool.service.RegistrationPoolListService;
import com.system.registrationPool.vo.ConfirmInfoVO;
import com.system.registrationPool.vo.RegistrationPoolLstVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 林
 */
@RestController
@RequestMapping("/registrationPoolList")
public class RegistrationPoolListController {
    @Autowired
    private RegistrationPoolListService registrationPoolListService;

    @PostMapping("/save")
    public boolean saveHandle(@RequestBody RegistrationPoolList registrationPoolList){
        return registrationPoolListService.saveRegistrationPoolList(registrationPoolList);
    }

    @DeleteMapping("/del/{id}")
    public boolean deleteHandle(@PathVariable("id") int id){
        return registrationPoolListService.removeRegistrationPoolListById(id);
    }

    @PutMapping("/update")
    public boolean updateHandle(@RequestBody RegistrationPoolList registrationPoolList){
        return registrationPoolListService.modifyRegistrationPoolList(registrationPoolList);
    }

    @GetMapping("/get/{id}")
    public RegistrationPoolList getHandle(@PathVariable("id") int id){
        return registrationPoolListService.getRegistrationPoolListById(id);
    }

    @GetMapping("/get/list")
    public List<RegistrationPoolList> listHandle(){
        return registrationPoolListService.listAllRegistrationPoolLists();
    }

    @GetMapping("/get/getRegistrationPoolListByPoolId/{poolId}")
    public List<RegistrationPoolList> getRegistrationPoolListByPoolId(@PathVariable("poolId") int poolId){
        return registrationPoolListService.findAllByPoolId(poolId);
    }

    @GetMapping("/get/findAllByArrangementId/{arrangementId}")
    public List<RegistrationPoolList> findAllByArrangementId(@PathVariable("arrangementId") int arrangementId){
        return registrationPoolListService.findAllByArrangementId(arrangementId);
    }

    @GetMapping("/get/findNumByArrangementId/{arrangementId}")
    public Integer findNumByArrangementId(@PathVariable("arrangementId") int arrangementId){
        return registrationPoolListService.findNumByArrangementId(arrangementId);
    }

    @GetMapping("/get/findLockNumByArrangementId/{arrangementId}")
    public Integer findLockNumByArrangementId(@PathVariable("arrangementId") int arrangementId){
        return registrationPoolListService.findLockNumByArrangementId(arrangementId);
    }

    @GetMapping("/get/findVoByArrangementId/{arrangementId}")
    public List<RegistrationPoolLstVO> findVoByArrangementId(@PathVariable("arrangementId") int arrangementId){
        return registrationPoolListService.findVoByArrangementId(arrangementId);
    }


    @PostMapping("/{id}/lock-number")
    public synchronized boolean lockNumber(@PathVariable("id") Integer poolListId) {
        return registrationPoolListService.lockNumber(poolListId);
    }

    @PostMapping("/{id}/release-number")
    public synchronized boolean releaseNumber(@PathVariable("id") Integer poolListId) {
        return registrationPoolListService.releaseNumber(poolListId);
    }

    @GetMapping("/getTime/{id}")
    public String getTime(@PathVariable("id") Integer poolListId) {
        return registrationPoolListService.getTime(poolListId);
    }

    @GetMapping("/getArrangementId/{id}")
    public Integer getArrangementId(@PathVariable("id") Integer poolListId) {
        return registrationPoolListService.getArrangementId(poolListId);
    }

    @GetMapping("/getDoctorInfo/{id}")
    public ConfirmInfoVO getDoctorInfo(@PathVariable("id") Integer poolListId) {
        return registrationPoolListService.getDoctorInfo(poolListId);
    }
}


